
#ifndef _PIT_h
#define _PIT_h

#include "zf_common_headfile.h"
// GPS FLASH
#define FLASH_SECTION_GPS       FLASH_SECTION_127       // Sectors for storing GPS latitude and longitude data; The last to last sector
#define FLASH_PAGE_LAT          FLASH_PAGE_3            // Page numbers used to store GPS latitude data; Last page
#define FLASH_PAGE_LON          FLASH_PAGE_2            // Page number used to store GPS longitude data; Second to last page number
// GPS
#define GPS_INITIAL_POINT       3
// hall encode
#define MeterSecond     0.000119650501
#define TimeConsersion  600 // 原 600

extern float detaYaw;
extern float encoder, V_old, get_speed_sum, meter_second, hall_dis;
extern float Yaw;//新建变量防止刚复制完后，立刻被WIT串口替换 
extern float ggyro_z;//新建变量防止刚复制完后，立刻被WIT串口替换
extern float gps_Yaw;//角度环记录读取gps时的yaw
typedef struct pid
{
	float   P;
	float   I;
	float   D;
	float   Error; 
	float   Error_pre; 
	float   Error_prepre; 
	float   Error_Rate; 
	float   Error_Ratepro; 
	float   Error_ADD; 
	float   Limit;
	float   Output;
    float   mid_value; 
}PID;

typedef struct GPS_message
{
    double  lat[200]; 
    double  lon[200]; 
    float   former_i_dis[200];		//上一点 与 I点 距离
    float   former_i_dir[200];		//上一点 与 I点 方位角
	float   former_i_Aoa[200];		//上一点 与 I点 方位角角度差
	int16   i;
}GPS_target;

enum
{
    State_go_straight	=	0xA0,
	State_go_curve_L	=	0XA1,
	State_go_curve_R	=	0xA2,
	
	State_dot_front     =	0xB0,
	State_dot_rear      =	0xB1,

	State_Invalid		=	0xC0,
	State_Valid			=	0xC1,

};

    
extern PID Servo_gyro_pid, Gyro_pid, Servo_Angle_pid;
extern GPS_target GPS_Data;

extern float Aoa_tar, Aoa_out, Aoa_former, dis_last, Aoa_former_last;
extern float Gyro_z, Gyro_exp_yaw, Gyro_com;
extern uint8 MOTION_State;

void Servo_Timer(void);
void PID_Iint(PID* PID_Gyro, PID* PID_Servo_Gyro, PID* Servo_Angle_pid);

void Encoder_Timer(void);
void Exercise_analysis(GPS_target* GPSData);
void GPS_inf_init(void);	                    // Initialization of the GPS storage structure
void GPS_dataup(void);                          // GPS data update
void GPS_recalculate(int16 current_i);			// GPS recalculate the data adjacent to the current point
void GPS_inf_reset(void);						// GPS information reset to 0
float Angle_limiter(float ANGLE);				// Angle limiter -180 ~ +180
void get_flash_gps(flash_section_enum flash_gps, flash_page_enum page_lat, flash_page_enum page_lon);	// Read the GPS information from the flash drive
void store_gps_flash(flash_section_enum flash_gps, flash_page_enum page_lat, flash_page_enum page_lon);	// Store GPS information in flash memory

float Loca_PID(PID* Increment, float Expect, float Actual);		// Location PID
float Incre_PID(PID* Incre, int16 Expect, int16 Actual);  		// Incremental PID
#endif

